package com.bjpowernode.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bjpowernode.entity.PmsBrand;
import com.bjpowernode.entity.UmsAdmin;
import com.bjpowernode.service.PmsBrandService;
import com.bjpowernode.vo.ResultJson;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * <p>
 * 品牌表 前端控制器
 * </p>
 *
 * @author zs
 * @since 2024-05-22
 */
@RestController
@RequestMapping("/pmsBrand")
public class PmsBrandController {
    @Resource
    PmsBrandService pmsBrandService;

    //分页查询
    @GetMapping("/list")
    public ResultJson<IPage<PmsBrand>> list(Integer pageNo, Integer pageSize, String name) throws InterruptedException {
        return ResultJson.success(pmsBrandService.getpmsBrandList(pageNo,pageSize,name));
    }

    //定义请求保存新增管理员方法，接收前端返回的参数，返回是否保存成功的结果
    @PostMapping("/save")
    public ResultJson<Boolean> save(String name, String description, MultipartFile file) {
        return ResultJson.success(pmsBrandService.save(name,description,file),"添加品牌成功");
    }

    //根据id指定查询管理员信息，目的是方便后面的修改操作
    @GetMapping("/getById")
    public ResultJson<PmsBrand> getById(String id) {
        return ResultJson.success(pmsBrandService.getById(id));
    }

    //定义请求保存修改管理员方法，接收前端返回的参数，返回是否保存成功的结果
    @PostMapping("/update")
    public ResultJson<Boolean> update(String id,String name, String description, MultipartFile file) {
        return ResultJson.success(pmsBrandService.update(id,name,description,file),"修改品牌成功");
    }

    //删除操作（不进行直接删除，而是控制启用禁用状态）
    @PostMapping("/delete")
    public ResultJson<Boolean> delete(String id,Boolean active) {
        return ResultJson.success(pmsBrandService.delete(id,active),active?"启用品牌成功":"禁用品牌成功");
    }
}
